<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #content {
            width: 180px;
            height: 280px;
            border: 1px solid #999;
            border-radius: 8px;
            margin-left: 50px;
            margin-bottom: 20px;
            text-align: center;
            line-height: 280px;
        }
        .num,
        .next,
        .pre{
            padding: 10px;
            border: 1px solid #999;
            cursor: pointer;
        }
        /* 一个元素有两个class。不能加空格，加了就是父子关系 */
        .num.active {
            background-color: #56a5f1;
            color: #fff;
        }
    </style>
</head>
<body>
    <div id="app">
        <div id="content">当前是第{{currPage}}页</div>
        <span class="pre" @click="pre">上一页</span>
        <span
            v-for="num in 5"
            :class="['num', {'active': num==currPage}]" 
            @click="changePage(num)"
        >第{{num}}页</span>
        <span class="next" @click="next">下一页</span>
    </div>
    <script src="./vue.js"></script>
    <script>
        var Page = {
            data() {
                return {
                    currPage: 1,
                }
            },
            methods: {
                changePage(num) {
                    this.currPage = num;
                },
                pre() {
                    if(this.currPage > 1) {
                        this.currPage --
                    }
                },
                next() {
                    if(this.currPage < 5) {
                        this.currPage ++
                    }
                }
            }
        }
        Vue.createApp(Page).mount('#app');
    </script>
</body>
</html>